﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using SpaceGame.Player;
using SpaceGame.Managers;

namespace SpaceGame.HUD
{
    public class Score : DrawableGameComponent
    {
        private SpriteFont m_Font;
        private SpriteBatch m_SpriteBatch;
        private PlayerShip m_Player;

        public Score(Game game, PlayerShip player) : base(game)
        {
            m_SpriteBatch = new SpriteBatch(game.GraphicsDevice);
            m_Player = player;
        }

        protected override void LoadContent()
        {
            m_Font = Game.Content.Load<SpriteFont>("Fonts/Tahoma");
            base.LoadContent();
        }

        public override void Draw(GameTime gameTime)
        {
            if (GameStateManager.GameState != GameState.Playing)
                return;

            Vector2 size = m_Font.MeasureString("Score: " + m_Player.Score);

            int drawX = Game.GraphicsDevice.PresentationParameters.BackBufferWidth - (int)size.X;
            int drawY = 0;

            m_SpriteBatch.Begin();

            m_SpriteBatch.DrawString(m_Font, "Score: " + m_Player.Score, new Vector2(drawX, drawY),
                Color.White);
            
            m_SpriteBatch.End();

            base.Draw(gameTime);
        }

    }
}
